import {reqSendOrder, reqGetPayInfo, reqGetPayStatement} from "@/api";
//Home模块
const state = {
    orderId: '',
    payInfo: {},
    resultCode: -1
}

const actions = {
    async sendOrder({commit}, {tradeNo, data}) {
        let result = await reqSendOrder(tradeNo, data)
        if (result.code === 200) {
            commit('SENDORDER', result.data)
            return 'success'
        } else {
            return Promise.reject(new Error('不能重复提交'))
        }
    },
    async getPayInfo({commit}, orderId) {
        let result = await reqGetPayInfo(orderId)
        if (result.code === 200) {
            commit('GETPAYINFO', result.data)
            return 'success'
        } else {
            return Promise.reject(new Error('fail'))
        }
    },
    async getPayStatement({commit}, orderId) {
        let result = await reqGetPayStatement(orderId)
        if (result.code === 200) {
            commit('GETPAYSTATEMENT', result.code)
            return 'success'
        } else {
            return Promise.reject(new Error('fail'))
        }
    }
}

const mutations = {
    SENDORDER(state, orderId) {
        state.orderId = orderId
    },
    GETPAYINFO(state, payInfo) {
        state.payInfo = payInfo
    },
    GETPAYSTATEMENT(state, resultCode) {
        state.resultCode = resultCode
    },
}

const getters = {}

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}

